<?php
session_start();
if (!isset($_SESSION['admin'])) { header('Location: index.php'); exit; }
// 统计项目数量
$projects = file_exists('../data/projects.json') ? json_decode(file_get_contents('../data/projects.json'), true) : [];
$projectCount = count($projects);
$appCount = $projectCount; // 每个项目视为一个APP
// 访问量、下载量
$statFile = '../data/stat.json';
$stat = file_exists($statFile) ? json_decode(file_get_contents($statFile), true) : ['visit'=>0,'download'=>0];
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>后台管理</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap/5.3.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container py-5">
    <h3 class="mb-4">后台管理</h3>
    <div class="row mb-4">
        <div class="col-md-3 col-6">
            <div class="card text-center">
                <div class="card-body">
                    <div class="h2 mb-1"><?=$projectCount?></div>
                    <div class="text-muted">项目数量</div>
                </div>
            </div>
        </div>
        <div class="col-md-3 col-6">
            <div class="card text-center">
                <div class="card-body">
                    <div class="h2 mb-1"><?=$appCount?></div>
                    <div class="text-muted">APP数量</div>
                </div>
            </div>
        </div>
        <div class="col-md-3 col-6">
            <div class="card text-center">
                <div class="card-body">
                    <div class="h2 mb-1"><?=$stat['visit']?></div>
                    <div class="text-muted">访问量</div>
                </div>
            </div>
        </div>
        <div class="col-md-3 col-6">
            <div class="card text-center">
                <div class="card-body">
                    <div class="h2 mb-1"><?=$stat['download']?></div>
                    <div class="text-muted">下载量</div>
                </div>
            </div>
        </div>
    </div>
    <div class="list-group mb-3">
        <a href="projects.php" class="list-group-item list-group-item-action">项目管理</a>
        <a href="change_password.php" class="list-group-item list-group-item-action">修改密码</a>
        <a href="logout.php" class="list-group-item list-group-item-action">退出登录</a>
    </div>
    <div class="alert alert-info mt-4">请先进入"项目管理"新建项目，再进行应用管理。</div>
</div>
</body>
</html> 